package com.fauks.study.msweb.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class ExceptionController {

    @RequestMapping("/null")
    public String nullError() {
        String name = null;
        System.out.println(name.length());
        return "ok";
    }

    //专门处理空指针异常
    @ExceptionHandler(NullPointerException.class)
    public ModelAndView nullPointerExceptionk(Exception ex) {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("error_nullpoint");
        mv.addObject("ex", ex);
        return mv;
    }
}
